# coding:utf-8
from flask import Flask
from flask import make_response
import model
import controller as ctrl

app = Flask(__name__)


@app.route('/')
def index():
    """
    博客首页
    :return: 返回博客主页面
    """
    return ctrl.get_page(1)


@app.route('/page/<int:page>')
def blog_list(page):
    """
    获取博客第 N 页列表
    :param page:
    :return: 返回博客列表页
    """
    return ctrl.get_page(page)


@app.route('/blog/<string:blog_name>')
def blog_frame(blog_name):
    """
    获取博客详情页面框架. 框架中包含了一个 iframe.
    :param blog_name:
    :return:
    """
    return ctrl.blog_frame(blog_name)


@app.route('/blog_content/<string:blog_name>')
def blog_content(blog_name):
    """
    获取指定博客内容
    :param blog_name:
    :return:
    """
    html = ctrl.blog_content(blog_name)
    if html is None:
        return make_response("Blog Not Found", 404)
    return html


if __name__ == '__main__':
    model.update()
    app.run(debug=True)
